<html> <script language=javascript> setTimeout('window.location="../view/sysadmin.php"',500) </script> </html>
<?php 
	header('Content-Type:text/html;charset=UTF-8');
	require('mysql.php');
	$auth =$_POST["auth"];
	
//	var_dump($auth);
	$sid=$_POST["sid"];
//	var_dump($sid);
//	echo "<br/>";
	$total_auth=null;
	foreach($auth as $n){
	$total_auth=$total_auth.$n;
//	echo $n.") 成功<br />";
}
//	echo '学号：'.$sid;
$sq="SELECT COUNT(*) FROM stuwithauthority where studentid='$sid'";
$q = mysql_query($sq);
$row = mysql_fetch_array($q);
if($row[0]>0){
	$sup="update stuwithauthority set authorityid='$total_auth' where studentid='$sid'";
	$que = mysql_query($sup);
	if($que){
	echo '权限设置成功! <a href="../view/sysadmin.php">返回管理页面</a>'."<br/>";
			}else{
		echo '更新失败。';
		}
}
else{
$sql = "insert into stuwithauthority values ('$sid','$total_auth')";    
$query = mysql_query($sql);

if($query){
//	header("Location:../view/sysadmin.php");
//	echo '<script>alert("权限设置成功！");</script>';
//	exit();
	echo '权限设置成功! <a href="../view/sysadmin.php">返回管理页面</a>'."<br/>";
}else{
	echo '数据插入失败。';
}
}
mysql_close();
?>
